<template>
  <nav
    class="
      navbar navbar-dark
      bg-primary
      navbar-expand-lg
      justify-content-between
      mb-4
      px-4
    "
  >
    <div class="w-75 mx-auto navbar">
      <router-link to="/" class="navbar-brand">专栏</router-link>
      <ul v-if="!user.isLogin" class="list-inline mb-0">
        <li class="list-inline-item">
          <button type="button" class="btn btn-outline-light" @click="signIn">
            登录
          </button>
        </li>
        <li class="list-inline-item">
          <button type="button" class="btn btn-outline-light">注册</button>
        </li>
      </ul>
      <ul v-else>
        <li class="list-inline-item">
          <dropdown :title="`你好 ${user.nickName}`">
            <dropdown-item
              ><router-link to="/create" class="dropdown-item" href="#"
                >新建文章</router-link
              ></dropdown-item
            >
            <dropdown-item
              ><router-link class="dropdown-item" :to="`/column/${user.column}`"
                >我的专栏</router-link
              ></dropdown-item
            >
            <dropdown-item
              ><a class="dropdown-item" href="#">编辑资料</a></dropdown-item
            >
            <dropdown-item
              ><a class="dropdown-item" href="#">退出登录</a></dropdown-item
            >
          </dropdown>
        </li>
      </ul>
    </div>
  </nav>
</template>
<script lang='ts'>
import { defineComponent, PropType } from "vue";
import Dropdown from "@/components/Dropdown.vue";
import DropdownItem from "./DropdownItem.vue";
import { useStore } from "vuex";
import { GlobalDataProps, UserProps } from "../utils/interface";
import { useRouter } from "vue-router";
export default defineComponent({
  name: "GlobalHeader",
  props: {
    user: {
      type: Object as PropType<UserProps>,
      required: true,
    },
  },
  components: { Dropdown, DropdownItem },
  setup() {
    const store = useStore<GlobalDataProps>();
    const router = useRouter();
    const signIn = () => {
      router.push("/login");
    };
    return {
      signIn,
    };
  },
});
</script>
<style scoped>
</style>